var Example = null;
var Count = 0;
var Current = 0;
var Timer = null;

function DisplayExample()
{
	Example = document.getElementsByClassName('headband_example');
	Count = Example.length;
	Current = parseInt(Math.random()*Count);
	Example[Current].style.opacity = 1;
	Example[Current].style.display = 'inline-block';
	setInterval('ChangeExample();', 12500);
}

function ChangeExample()
{
	clearInterval(Timer);
	Timer = setInterval('FadeOut();', 50);
}

function FadeOut()
{
	var o = parseFloat(Example[Current].style.opacity);
	if(o <= 0)
	{
		clearInterval(Timer);
		ChangeExample2();
		return;
	}
	o = Math.max(0, 10*o - 1)/10;
	Example[Current].style.opacity = o;
}

function ChangeExample2()
{
	Example[Current].style.display = 'none';
	Current++;
	if(Current == Count) Current = 0;
	Example[Current].style.display = 'inline-block';
	Example[Current].style.opacity = 0;
	Timer = setInterval('FadeIn();', 50);
}

function FadeIn()
{
	var o = parseFloat(Example[Current].style.opacity);
	if(o >= 1)
	{
		clearInterval(Timer);
		return;
	}
	o = Math.min(10, 10*o + 1)/10;
	Example[Current].style.opacity = o;
}